package ua.exchangeratesukraine.ui.fragment;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;

public class DateDialogFragment extends DialogFragment {
	private static Calendar						sDate	= Calendar.getInstance();
	private static DateDialogFragmentListener	sListener;

	public static DateDialogFragment newInstance(Context context, int titleResource, Calendar date) {
		DateDialogFragment dialog = new DateDialogFragment();
		sDate = date;
		Bundle args = new Bundle();
		args.putInt("title", titleResource);
		dialog.setArguments(args);
		return dialog;
	}

	public static DateDialogFragment newInstance(Context context) {
		DateDialogFragment dialog = new DateDialogFragment();
		return dialog;
	}

	public Dialog onCreateDialog(Bundle savedInstanceState) {
		return new DatePickerDialog(getActivity(), dateSetListener, sDate.get(Calendar.YEAR),
				sDate.get(Calendar.MONTH), sDate.get(Calendar.DAY_OF_MONTH));
	}

	OnDateSetListener	dateSetListener	= new OnDateSetListener() {
				@Override
				public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
					sListener.dateDialogFragmentDateSet(year, monthOfYear, dayOfMonth);
				}
			};

	public void setDateDialogFragmentListener(DateDialogFragmentListener listener) {
		sListener = listener;
	}
}